const baseUrl = "https://meituan.thexxdd.cn/api";
import { Base64 } from "js-base64";

const getToken = () => {
  const token = uni.getStorageSync("token") || "";
  const a = token + ":";
  const b = Base64.encode(a);
  return "Basic " + b;
};

export const http = (config: any) => {
  return new Promise((resolve, reject) => {
    uni.request({
      url: baseUrl + config.url,
      method: config.method || "GET",
      data: config.data || {},
      header: { Authorization: getToken() },
      success: (res) => {
        return resolve(res.data);
      },
      fail: (err) => {
        uni.showToast({
          title: "未知错误",
          icon: "none",
        });
        return reject(err);
      },
      complete: () => {
        // uni.hideLoading();
      },
    });
  });
};
